package cn.com.io.day20151210;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * Created by Administrator on 2015/12/10.
 */
public class ReadFromProcess {
    public static void main(String[] args) throws IOException {
        BufferedReader reader= null;
        try {
            Process process = Runtime.getRuntime().exec("javac");//运行javac命令，返回运行该命令的子进程
            reader = new BufferedReader(new InputStreamReader(process.getErrorStream(),"GBK"));//以process进程的错误流创建BufferedReader对象，这个错误流对本程序是输入流，对process进程是输出流
            String buff = null;
            while((buff = reader.readLine()) !=null){
                //循环读取process进程的错误输出
                System.out.println(buff);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            if(reader != null){
                reader.close();
            }
        }
    }
}
